package cn.edu.sjtu.se.dslab.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.sjtu.se.dslab.action.bean.PageBean;
import cn.edu.sjtu.se.dslab.component.method.ComponentInterface;
import cn.edu.sjtu.se.dslab.dao.IComponentInterfaceDao;
import cn.edu.sjtu.se.dslab.exception.DBException;
import cn.edu.sjtu.se.dslab.service.IComponentInterfaceService;

@Service("componentInterfaceService")
@Transactional
public class ComponentInterfaceServiceImpl implements
		IComponentInterfaceService {

	@Resource(name = "componentInterfaceDao")
	private IComponentInterfaceDao componentInterfaceDao;

	@Override
	public boolean addComponentInterface(
			cn.edu.sjtu.se.dslab.component.method.ComponentInterface componentInterface) {
		// TODO Auto-generated method stub
		componentInterfaceDao.save(componentInterface);
		return true;
	}

	@Override
	public cn.edu.sjtu.se.dslab.component.method.ComponentInterface getComponentInterfaceById(
			long id) {
		// TODO Auto-generated method stub
		ComponentInterface componentInterface = componentInterfaceDao
				.queryById(id);
		return componentInterface;
	}

	@Override
	public boolean updateComponentInterface(
			cn.edu.sjtu.se.dslab.component.method.ComponentInterface componentInterface) {
		// TODO Auto-generated method stub
		componentInterfaceDao.update(componentInterface);
		return true;
	}

	@Override
	public List<ComponentInterface> getAllComponentInterface() {
		// TODO Auto-generated method stub
		return componentInterfaceDao.queryAll();
	}

	@Override
	public PageBean<ComponentInterface> getPageBean(int pageNo)
			throws DBException {
		// TODO Auto-generated method stub
		return componentInterfaceDao.queryByPageNum(pageNo);
	}

	@Override
	public ComponentInterface getComponentInterfaceByUri(String uri) {
		// TODO Auto-generated method stub
		return componentInterfaceDao.queryByUri(uri);
	}

	@Override
	public boolean deleteComponentInterfaceById(long id) {
		// TODO Auto-generated method stub
		componentInterfaceDao.deleteById(id);
		return true;
	}

	@Override
	public boolean deleteComponentInterface(
			ComponentInterface componentInterface) {
		// TODO Auto-generated method stub
		componentInterfaceDao.delete(componentInterface);
		return true;
	}

	@Override
	public boolean deleteComponentInterfaceByUri(String uri) {
		// TODO Auto-generated method stub
		componentInterfaceDao.deleteByUri(uri);
		return false;
	}

	@Override
	public  List<ComponentInterface>  getComponentInterfaceByProperty(String text) {
		// TODO Auto-generated method stub
		return componentInterfaceDao.queryByProperty(text);
	}

	@Override
	public List<ComponentInterface> getComponentInterfaceByType(String type) {
		// TODO Auto-generated method stub
		return componentInterfaceDao.queryByType(type);
	}

}
